import { baseURL } from '@/config'
import axios from 'axios'

const request = axios.create({
  baseURL,
  timeout: 5000
})

request.interceptors.response.use((response) => {
  if (response.status !== 200) {
    return Promise.reject(response)
  }
  const res = response.data
  const code = res.code
  let message = res.message || '请求失败'
  if (code === 0) {
    return res.data
  } else {
    return Promise.reject(message)
  }
})

export { request }
